const CryptoJS = require('crypto-js')

const lF = "zxcvbnmlkjhgfdsaqwertyuiop0987654321QWERTYUIOPLKJHGFDSAZXCVBNM"
    , fne = lF + "-@#$%^&*+!";

function dne(e, t) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * e + 1, 10);
        case 2:
            return parseInt(Math.random() * (t - e + 1) + e, 10);
        default:
            return 0
    }
}

function hne(e) {
    return [...Array(e)].map(() => lF[dne(0, 61)]).join("")
}

function stringify(e) {
    let result = '';
    Object.keys(e).forEach((key) => {
        result += key + "=" + encodeURIComponent(e[key]) + "&"
    });
    return result.substring(0, result.length - 1)
}

function pne(e) {
    let t = "";
    return typeof e == "object" ? t = Object.keys(e).map(n => `${n}=${e[n]}`).sort().join("&") : typeof e == "string" && (t = e.split("&").sort().join("&")),
        t
}

function get_data(data, t) {
    let p = stringify(data),
        n = hne(16),
        k = "k8tUyS$m",
        r = pne(p);
    let str = n + k + decodeURIComponent(r) + t;
    // console.log(str)
    let sign = CryptoJS.SHA256(str).toString()
    // 16位随机串，签名
    return [n, sign]
}

// data = {
//     "type": "trading-type",
//     "openConvert": false,
//     "keyword": "",
//     "siteCode": "44",
//     "secondType": "A",
//     "tradingProcess": "",
//     "thirdType": "[]",
//     "projectType": "",
//     "publishStartTime": "",
//     "publishEndTime": "",
//     "pageNo": 5,
//     "pageSize": 10
// }
//
// console.log(get_data(data, 1711506548835))